// 特惠卖场
<template>
  <div class="referentialMarket">
    <nav-login></nav-login>
    <home-seach></home-seach>
    <goods-nav :navindex="navindex"></goods-nav>
    <div class="w1200">
      <div class="banner">
        <img src="@/assets/images/2019pic03.jpg">
      </div>

      <div class="content">
        <!-- 左侧导航 -->
        <div class="content-left">
          <div>
            <h2>
              <i class="iconfont myicon">&#xe616;</i>
              <span>特惠卖场</span>
            </h2>
            <el-tree
              accordion
              node-key="id"
              page-size="20"
              :data="treeData"
              :props="defaultProps"
              highlight-current
              @node-click="handleNodeClick"
            ></el-tree>
          </div>
        </div>
        <!-- 右侧商品 -->
        <div class="content-right" v-loading="loading">
          <template v-if="goods.length">
            <ul>
              <li
                v-for="item in goods"
                :key="item.id"
                @click="jumpDetails(item.id,item.goods_id,item)"
              >
                <img v-lazyload="item.goods_logo" src="@/assets/logo/loading.png">
                <div class="w150">
                  <p>{{ item.goods_title }}</p>
                  <div>
                    <b>￥ {{ item.selling_price }}</b>
                    <del>￥ {{ item.market_price }}</del>
                  </div>
                </div>
              </li>
            </ul>
            <el-pagination
              background
              layout="prev, pager, next"
              :page-count="last_page"
              @current-change="currentChange"
            ></el-pagination>
          </template>
          <no-data :msg="msg" v-else />
        </div>
      </div>
    </div>
    <bottom-nav></bottom-nav>
    <home-footer></home-footer>
  </div>
</template>
<script>
export default {
  name: "referentialMarket",
  data() {
    return {
      msg: '暂无相关数据...',
      loading: false,
      last_page: 1,  //
      page: 1,
      navindex: 3, // 总nav 传值
      treeData: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      nav: [
        "气动元件",
        "直线运动类",
        "传动类",
      ],
      indexn: 0, // 初始化
      goods: []
    }
  },

  methods: {
    // 左侧点击事件
    async handleNodeClick(data) {
      this.loading = true
      if (!data.children) {
        let page = this.page
        let id = data.id
        this.$store.commit("MarketDataId", id)
        this.$store.commit("MarketDataPage", page)
        // console.log(id)
        let res = await this.$http({
          method: 'post',
          url: '/api/index/api/specialOffer',
          data: {
            id,
            page
          }
        })
        if (res.data.State.Code == 200) {
          if (res.data.data) {
            this.last_page = res.data.last_page
            this.goods = res.data.data
            this.loading = false
          }
        } else {
          this.goods = []
          this.loading = false
        }
      }else{
        this.loading = false
      }
    },

    // 分页点击事件
    async currentChange(page) {
      this.loading = true
      this.page = page
      this.$store.commit("MarketDataPage", page)
      let id = this.$store.state.MarketDataId
      let res = await this.$http({
        method: 'post',
        url: '/api/index/api/specialOffer',
        data: {
          id,
          page
        }
      })
      if (res.data.State.Code == 200) {
        if (res.data.data) {
          this.goods = res.data.data
          this.loading = false
        }
      } else {
        this.goods = []
        this.loading = false
      }
    },

    // 左侧导航初始化
    async navInit() {
      let res = await this.$http({
        method: "post",
        url: '/api/index/api/specialOfferCate',
        data: {}
      })
      if (res.data.State.Code == 200) {
        this.treeData = res.data.data
      }
    },

    changes(event) {
      this.indexn = event
    },

    async dataChanges() {
      this.loading = true
      let page = this.page || 1
      let id = this.$store.state.MarketDataId || ''
      console.log(page, id)
      this.$store.commit("MarketDataId", id)
      this.$store.commit("MarketDataPage", page)
      let res = await this.$http({
        method: 'post',
        url: '/api/index/api/specialOffer',
        data: {
          id,
          page
        }
      })
      if (res.data.State.Code == 200) {
        if (res.data.data) {
          this.last_page = res.data.last_page
          this.goods = res.data.data
          this.loading = false
        }
      } else {
        this.goods = []
        this.loading = false
      }

    },

    jumpDetails(id, pid, item) {
      this.$router.push({
        name: "productDetails",
        params: {
          id,
          pid,
          item
        }
      })
    }

  },
  mounted() {
    this.navInit()
    this.dataChanges()
  }
}
</script>
<style lang="scss" scoped>
.referentialMarket {
  .w1200 {
    width: 1200px;
    margin: auto;
    .banner {
      width: 100%;
      height: 290px;
      margin-bottom: 30px;
      img {
        width: 100%;
        height: 290px;
      }
    }
    .content {
      width: 1200px;
      display: flex;
      flex-direction: row;
      .content-left {
        /deep/ .el-tree {
          .el-tree-node__content {
            .el-tree-node__label {
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
              font-weight: bold;
            }
          }
        }
        div {
          background: #f1f1f1;
          width: 212px;
          h2 {
            width: 100%;
            height: 110px;
            background-color: #0a83e7;
            color: #fff;
            text-align: center;
            letter-spacing: 2px;
            padding-top: 10px;

            .myicon {
              font-size: 40px;
              font-weight: normal;
            }
            span {
              display: block;
              line-height: 32px;
            }
          }
          ol {
            padding: 15px 0px;
            li {
              background: #fff;
              margin: 6px 15px;
              line-height: 32px;
              display: flex;
              flex-direction: row;
              justify-content: space-between;
              padding: 0 10px;
              cursor: pointer;
              letter-spacing: 1px;
              font-weight: bold;
              i {
                color: #888888;
                font-weight: bold;
              }
              &:hover {
                color: #ff7e00;
              }
              &:hover i {
                color: #ff7e00;
              }
            }
            .active {
              color: #ff7e00;
              & {
                i {
                  color: #ff7e00;
                }
              }
            }
          }
        }
      }
      .content-right {
        width: 988px;
        ul {
          display: flex;
          flex-direction: row;
          // justify-content: space-between;
          flex-wrap: wrap;
          li {
            width: 184px;
            border: 1px solid #eeeeee;
            position: relative;
            margin: 0px 5.8px 20px 5.8px;
            cursor: pointer;
            &:hover {
              border: 1px solid #ff9999;
            }

            img {
              width: 110px;
              height: 110px;
              margin-left: 37px;
              margin-top: 12px;
              margin-bottom: 12px;
            }
            i {
              display: block;
              position: absolute;
              right: 15px;
              top: 15px;
              width: 64px;
              height: 64px;
              background: rgba($color: #ff0000, $alpha: 0.6);
              border-radius: 50%;
              color: #fff;
              text-align: center;
              line-height: 64px;
              font-size: 20px;
              font-weight: bold;
            }
            .w150 {
              width: 169px;
              margin: auto;
              overflow: hidden;
              text-align: center;
              p {
                line-height: 40px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              }
              span {
                display: block;
                color: #8e8e8e;
                line-height: 20px;
                margin-bottom: 10px;
              }
              div {
                line-height: 44px;
                border-top: 1px #d6d6d6 dashed;
                display: flex;
                flex-direction: row;
                justify-content: space-around;
                b {
                  color: #ff0000;
                  font-size: 16px;
                }
                del {
                  font-size: 12px;
                }
              }
            }
          }
          .emply {
            width: 100%;
            line-height: 300px;
            text-align: center;
            font-size: 100px;
            color: #ffca997e;
          }
        }
        .el-pagination {
          text-align: center;
          margin-top: 20px;
        }
      }
    }
  }
}
</style>


